<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="button" name="" id="btn" value="add">
  <ul id="list">
    <li class="item">1</li>
    <li class="item">2</li>
    <li class="item">3</li>
    <li class="item">4</li>
  </ul>
  <script lang="javascript">
  // 事件冒泡的应用 
  // 事件委托：由于事件会在冒泡阶段向上传播到父节点，因此可以把子节点的监听函数定义在父节点上，由父节点的监听函数统一处理多个子节点的事件。
  let num=4;
  const list =document.getElementById('list')
  document.getElementById('btn').onclick = function(){
    num++;
    const oLi = document.createElement('li');
    oLi.innerHTML = `${num}`;
    list.appendChild(oLi)
  }
  document.getElementById('list').addEventListener('click',function(e){
    var event = e||window.event;
    var target =  event.target||event.srcElement;
    console.log(event.currentTarget,target);
    if(target.nodeName.toLowerCase()==='li'){
      console.log('the content is:',target.innerHTML);
    }
  })
  </script>
</body>
</html>